import { ApiProperty } from '@nestjs/swagger';
import { modelOptions, prop, Ref } from '@typegoose/typegoose';
import { Category } from './category.model';

@modelOptions({
  schemaOptions: {
    timestamps: true,
  },
})
export class Book {
  @ApiProperty({ description: '图书名称', example: '红楼梦' })
  @prop({ required: true })
  name: string;

  @ApiProperty({ description: '作者', example: '曹雪芹' })
  @prop({ required: true })
  author: string;

  @ApiProperty({
    description: '图书分类ID',
    example: 'xxxxxx',
  })
  @prop({ required: true, ref: 'Category' })
  categories: Ref<Category>[];

  @ApiProperty({ description: '库存或数量', example: '1' })
  @prop({ required: true })
  number: number;

  @ApiProperty({ description: '单价', example: '49' })
  @prop({ required: true })
  price: number;

  @ApiProperty({ description: '图书封面地址', example: '/xxx' })
  @prop()
  image: string;

  @ApiProperty({ description: '图书简介', example: 'xxxxxx' })
  @prop()
  description: string;

  @ApiProperty({ description: '销量', example: '0' })
  @prop({ default: 0 })
  sales: number;
}
